package com.invengo.testrfid.app.view;

import android.content.Context;
import android.opengl.Visibility;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.invengo.testrfid.MyApplication;
import com.invengo.testrfid.R;

public class PreOrNextView extends RelativeLayout {

    private RelativeLayout re_pre;

    private RelativeLayout re_next;

    private TextView tv_next;

    public PreOrNextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        View inflate = LayoutInflater.from(context).inflate(R.layout.view_next_pre, this);
        this.re_pre = inflate.findViewById(R.id.re_pre);
        this.re_next = inflate.findViewById(R.id.re_next);
        this.tv_next = inflate.findViewById(R.id.tv_next);
    }

    public void initView(boolean isShowPre, boolean nextIsClickable) {

        if (isShowPre) {
            re_pre.setVisibility(VISIBLE);
        } else {
            re_pre.setVisibility(GONE);
        }

        if (nextIsClickable) {

            re_next.setClickable(true);
            tv_next.setTextColor(MyApplication.getContext().getResources().getColor(R.color.orange));
        } else {

            re_next.setClickable(false);
            tv_next.setTextColor(MyApplication.getContext().getResources().getColor(R.color.gray));
        }
    }

    public void initText(String nextTitle) {

        tv_next.setText(nextTitle);
    }

    public void setOnClickListenser(final PreOrNextCallback preOrNextCallback) {

        re_pre.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                preOrNextCallback.onPreClick();
            }
        });

        re_next.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                preOrNextCallback.onNextClick();
            }
        });
    }

    public static class PreOrNextCallback {

        public void onPreClick() {
        }

        ;

        public void onNextClick() {
        }

        ;
    }
}
